<?php

class Sender
{
  public $users = array();
  
  public function initUsers()
  {
    //$f = file_get_contents('school_mails.txt');
    
    /*foreach(explode("\n",$f) as $line)
    {
      if(strlen($line)>0)
      {
        $this->users []= User::createFromLine($line);
      }
    }*/
    
    foreach(Db::fetchAll("SELECT * FROM schools") as $row)
    {     
      
      $user = User::createFromRow($row);
      //moze byt ze ziaden s mailov nebol vyplneny
      if(strlen($user->email) > 0)   
        $this->users[] = $user;    
    }    
    return $this;
  }

  public function sendAll()
  {
    foreach($this->users as $user)
    {
      if($user->hasValidEmail())
      {
        $user->generateUrl()->send();
      }
      else
      {
        echo "Invalid email: " . $user->email;
      }
    }
    return $this;
  }
}

?>
